var commentNum;
var userCompleteCount;
var commentUserDatas;
var comments;
var getCommentfromServlet=function ()
{
    var jObj = new Object();
    jObj.id = eventID;
    httpPost('getcomments',jObj,getCommentComplete);
}
var getCommentComplete = function(data)
{
    var response = JSON.parse(data);
    response = response.comments;
    if(response)
    {
        
        commentNum =response.length;
        commentCompleteCount = 0;
        userCompleteCount=0; 
        commentUserDatas = new Array(commentNum);
        comments = response;
        for(var i=0;i<commentNum;i++)
        {
            getUserData(response[i].user,commentUserDatas,i);
        }
    }
    else 
    {
        commentNum =0;
        showSingleEvent(currentEventObj);
    }
}
var getCommentFBUserComplete = function()
{
  showSingleEvent(currentEventObj);
}
function showSingleEvent(evt)
{
    console.log('showsingle');
    $('.slideframe').hide();
    var outputString="";
    var raw = evt.rawEvent;
    eventID = evt.id;
    outputString+="<div class='event' id="+evt.i+">";
                        if(checkImg(evt.picture.data.url))
                        {
                            outputString+=
                            "<div class='image' style='float:left' onclick='window.open(,)'>"
                                +"<img src="
                                + evt.picture.data.url
                                +">"
                            +"</div>";
                        }
                        outputString+=
                         "<div style='float:right'>"
                                +"<input type='button' class='likeBtn' onclick='return false'>"
                                +"<p class='interestedNumber'>"+raw.interestedNumber+"人覺得有趣</p>"
                                +"<div></div>"
                                +"<div onclick='getfriendlist()' style='cursor:pointer'>邀請</div>"
                            +"</div>" 
                             
                        +"<div class='title'>"
                       
                            +"<h1 class='title' >"+evt.name+"</h1>"
                           +"<hr/>"
                        +"</div>"
                        +"<div class = 'discription'>"
                            +"<div>活動資訊:"+evt.description+"</div>"
                            +"<div>時間:"+evt.start_time+"</div>"
                            +"<div>地點:"+evt.location+"</div>"
                        +"</div>"
                        
                       +"<hr />"
                       +"<div id = commentfield>"
                       +"<h3>Comments</h3>";
                       for(var i=0;i<commentNum;i++)
                       {
                           outputString+=
                           "<div id = comment"+i+">"
                           +"<img class = 'commentimg' src = "+commentUserDatas[i].picture.data.url+">"
                           +"<a href='https://www.facebook.com/"+comments[i].user+"'class='commentname'>"+commentUserDatas[i].name+"</a>"
                           +"<p class='commentcontent'>"+comments[i].comment+"</p>"
                           +"<hr/>"
                           +"</div>";
                       }
                       
                       outputString+=
                            "<form class='comment' onsubmit='return false'>"
                               +" <input placeholder='你覺得?' type='text' id='commentText' />"
                            +"</form>"
                        +"</div>"
                      +"</div>"
                      +"<div id='back' class = 'back'>回列表</div>";
                      
    eventContent.innerHTML = outputString;
    enableComment();
    $('#back').click(function(){
        loadEvents();
    })
    if(rawEvent[evt.i].userlikeit==1)
     $('.likeBtn').css('background-image','url(img/likebtn.png)');
    likeEnable();
    
    
}
